package m3f.data;

import m3f.io.CachedMinibatchLoader;
import m3f.matrix.Minibatch;

public class SingleCachedLoader implements SingleDataProvider {
	
	private CachedMinibatchLoader loader;
	private int minibatchSize;
	
	public SingleCachedLoader(String file, boolean normalizeVectors){
		loader = new CachedMinibatchLoader(file, normalizeVectors);
		(new Thread(loader)).start();
	}

	@Override
	public boolean hasMoreData() {
		return loader.hasData();
	}

	@Override
	public Minibatch next() {
		return loader.nextMinibatch(minibatchSize);
	}

	@Override
	public void reset(boolean randomized) {
		long seed = 0;
		if(randomized)
			seed = System.currentTimeMillis();
		loader.reset(seed);
	}

	@Override
	public void setMinibatchSize(int size) {
		this.minibatchSize = size;
	}

	@Override
	public int getMinibatchSize() {
		return minibatchSize;
	}

	@Override
	public int matrixRows() {
		return loader.getMatrixRows();
	}

	@Override
	public int features() {
		return loader.getVectorSize();
	}

}
